package com.easyJava.utils;

import lombok.extern.slf4j.Slf4j;

import java.io.IOException;
import java.io.InputStream;
import java.io.InputStreamReader;
import java.util.*;

@Slf4j
public class PropertiesUtils {
    private static Properties properties = new Properties();
    private static Map<String, String> propertiesMap = new HashMap<>();

    static {
        InputStream in = null;
        try {
            in = PropertiesUtils.class.getClassLoader().getResourceAsStream("application.properties");
            properties.load(in);

            Iterator<Object> iterator = properties.keySet().iterator();
            while(iterator.hasNext()){
                String key = (String) iterator.next();
                String value = properties.getProperty(key);
                propertiesMap.put(key, value);
            }
        }catch (Exception e){
            e.printStackTrace();
            log.error("获取配置失败");
        }finally {
            if(in != null){
                try {
                    in.close();
                } catch (IOException e) {
                    e.printStackTrace();
                }
            }
        }
    }

    public static String getProperties(String key){
        return propertiesMap.get(key);
    }

}
